<?php
# =====================================
# 作者：老曹  QQ:1484743
# 版权声明：本程序为个人原创、开源程序，禁止用于任何违法用途，任何违法用途均与作者无关。
# 仅限学习交流，转载请注明出处。如需商用请联系作者。
# =====================================
require_once __DIR__ . '/../core/db.php';
header('Content-Type: application/json');
$hostId = isset($_GET['hostId']) ? intval($_GET['hostId']) : 0;
if ($hostId <= 0) {
    http_response_code(400);
    echo json_encode(['error' => 'hostId参数无效']);
    exit;
}
$db = new DB();
$sql = 'SELECT d.device, d.model, d.serial, h.score, h.status, h.abnormal_metrics, h.assess_time FROM disks d LEFT JOIN health_assessments h ON d.disk_id = h.disk_id WHERE d.host_id = ? ORDER BY h.assess_time DESC';
$stmt = $db->prepare($sql);
$stmt->bind_param('i', $hostId);
$stmt->execute();
$stmt->bind_result($device, $model, $serial, $score, $status, $abnormal, $assess_time);
$result = [];
while ($stmt->fetch()) {
    $result[] = [
        'device' => $device,
        'model' => $model,
        'serial' => $serial,
        'score' => $score,
        'status' => $status,
        'abnormal' => $abnormal,
        'assess_time' => $assess_time
    ];
}
$stmt->close();
$db->close();
echo json_encode($result); 